#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2022/6/27 下午5:32
# @Author  : qiufengfeng
# @File    : dialogue_copurs_loader_task.py
# @Description :


def task_dialogue_classify_ner_getlabel( text_list, labels):
    '''
    将 labels转化为 key_index和label
    :param text_list:
    :param labels:
    :return:
    '''
    current_index = 0
    key_indexs = []
    new_labels = []
    for text_index, text in enumerate(text_list):
        sub_key_index = []
        sub_label = []
        for label in labels:
            # label格式（start,end，label）
            if label[0] >= current_index and label[1] <= current_index + len(text):
                sub_key_index.append((label[0] - current_index, label[1] - current_index))
                if len(label) == 3:
                    sub_label.append(label[2])

        key_indexs.append(sub_key_index)
        new_labels.append(sub_label)

        current_index += len(text)+1

    return key_indexs, new_labels
